import 'package:EZ_Batter/src/tool/assets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

class SearchItem extends StatefulWidget {
  final DSPeripheral device;
  Function() onSelect;
  Function() onPressLongToChangeName;
  SearchItem({super.key, required this.device, required this.onSelect, required this.onPressLongToChangeName});

  @override
  State<SearchItem> createState() => _SearchItemState();
}

class _SearchItemState extends State<SearchItem> {
  bool get isconncet {
    return widget.device.peripheral?.result.device.isConnected ?? false;
  }

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
      return GestureDetector(
        onTap: () => widget.onSelect(),
        onLongPress: () => widget.onPressLongToChangeName(),
        child: Container(
          width: constraints.maxWidth,
          height: 40,
          color: Color_Bottom_bg,
          child: Stack(
            children: [
              ///图标
              // Positioned(
              //   left: 20,
              //   top: 0,
              //   bottom: 0,
              //   child: Center(
              //     child: Image.asset(height: 20, isconncet ? assets.light_on : assets.light_off),
              //   ),
              // ),

              ///设备名字
              Positioned(
                left: 20,
                top: 0,
                bottom: 0,
                child: Center(
                  child: Text(
                    widget.device.peripheral?.result.device.platformName ?? '',
                    style: TextStyle(fontSize: 13, color: isconncet ? Color_theme : Colors.white),
                  ),
                ),
              ),

              ///设备自定义名字
              // Positioned(
              //   right: 70,
              //   top: 0,
              //   bottom: 0,
              //   child: widget.isManager
              //       ? Container(height: 0)
              //       : Center(
              //           child: Text(
              //             widget.device.name,
              //             textAlign: TextAlign.right,
              //             style: TextStyle(fontSize: 13, color: isconncet ? Color_select_btn : Colors.white),
              //           ),
              //         ),
              // ),

              ///switch开关
              Positioned(
                right: 10,
                top: 6,
                bottom: 6,
                child: Image.asset(
                  isconncet ? assets.ble_on : assets.ble_off,
                  width: 30,
                ),
              ),

              ///下划线
              Positioned(
                left: 0,
                right: 0,
                bottom: 0,
                child: SizedBox(
                  height: 0.5,
                  child: Container(color: Color_line_view),
                ),
              ),
            ],
          ),
        ),
      );
    });
  }
}
